<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <form action="index.php?r=config" id="form-list" method="post">
                    <input type="hidden" name="actionType" value="">
                    <input type="hidden" name="plug_id" value="">
                    <div class="table-responsive">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>标题</th>
                                <th>描述</th>
                                <th>版本</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            foreach ($plugins as $plugin) {
                                ?>
                                <tr>
                                    <td><?php echo $plugin['title']; ?></td>
                                    <td><?php echo $plugin['description']; ?></td>
                                    <td><?php echo $plugin['version']; ?></td>
                                    <td>
                                        <input type="hidden" value="<?php echo $plugin['controller']; ?>" name="controller_<?php echo $plugin['id']; ?>">
                                        <input type="hidden" value="<?php echo $plugin['version']; ?>" name="version_<?php echo $plugin['id']; ?>">
                                        <?php
                                        if (array_key_exists($plugin['id'], $installed)) {
                                            if($installed[$plugin['id']]['ismust']!=1){
                                                ?>
                                                <button type="button" id="uninstall-<?php echo $plugin['id']; ?>"  class="btn btn-primary btn-sm m-l-5"
                                                        onclick="uninstall('<?php echo $plugin['id']; ?>')">卸载
                                                </button>
                                                <?php
                                            }else{
                                                ?>
                                                <button type="button" class="btn btn-danger btn-sm m-l-5">必要插件</button>
                                                <?php
                                            }
                                        } else {
                                            ?>
                                            <button type="button" id="install-<?php echo $plugin['id']; ?>" class="btn btn-primary btn-sm m-l-5"
                                                    onclick="install('<?php echo $plugin['id']; ?>')">安装
                                            </button>
                                            <?php
                                        }
                                        ?>
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    function uninstall(plugid) {
        var controller = $("input[name=controller_"+plugid+"]").val();
        $("#uninstall-"+plugid).prop("disabled","disabled");
        $.post("index.php?r=plugins/"+controller+"/uninstall",null,function (res) {
            if(res.code == 10000){
                window.location.reload();
            }
        },'json');
    }
    function install(plugid) {
        var controller = $("input[name=controller_"+plugid+"]").val();
        $("#install-"+plugid).prop("disabled","disabled");
        $.post("index.php?r=plugins/"+controller+"/install",null,function (res) {
            if(res.code == 10000){
                window.location.reload();
            }
        },'json');
    }
</script>
